﻿using MES.Desktop.Entities;
using MES.Desktop.IDataAccess;
using MES.Desktop.IService;
using MES.Desktop.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MES.Desktop.Service
{
    public class RoleService : ServiceBase, IRoleService
    {
        IRoleAccess _roleAccess;
        public RoleService(IRoleAccess roleAccess)
        {
            _roleAccess = roleAccess;
        }

        public bool CheckRoleName(string roleName, int id)
        {
            string json = _roleAccess.CheckRoleName(roleName, id);
            return this.GetResult<bool>(json);
        }

        public int Delete(int[] ids)
        {
            string json = JsonUtil.Serializer(ids);
            json = _roleAccess.Delete(json);
            return this.GetResult<int>(json);
        }

        public int DeleteRoleUser(int rid, int uid)
        {
            string json = _roleAccess.DeleteRoleUser(rid, uid);
            return this.GetResult<int>(json);
        }

        public RoleEntity[] GetAllRoles(string key = "none")
        {
            string json = _roleAccess.GetAllRoles(key);
            return this.GetResult<RoleEntity[]>(json);
        }

        public RoleEntity[] GetRoleByIds(int[] ids)
        {
            string json = JsonUtil.Serializer(ids);
            json = _roleAccess.GetRoleByIds(json);

            return this.GetResult<RoleEntity[]>(json);
        }

        public int UpdateRole(RoleEntity role)
        {
            string json = JsonUtil.Serializer(role);
            json = _roleAccess.Update(json);
            return this.GetResult<int>(json);
        }

        public int UpdateRoleMenus(RoleMenuEntity[] roleMenus)
        {
            string json = JsonUtil.Serializer(roleMenus);
            json = _roleAccess.UpdateRoleMenus(json);
            return this.GetResult<int>(json);
        }

        public int UpdateRoleUsers(RoleUserEntity[] roleUsers)
        {
            string json = JsonUtil.Serializer(roleUsers);
            json = _roleAccess.UpdateRoleUsers(json);
            return this.GetResult<int>(json);
        }
    }
}
